package com.cloudlinkscm.base.authcenter.dao;

import com.cloudlinkscm.base.authcenter.mapper.UserRoleRelationMapper;
import com.cloudlinkscm.base.authcenter.model.Role;
import com.cloudlinkscm.base.authcenter.model.UserRoleRelation;
import com.cloudlinkscm.loms.framework.dao.GenericBizDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author : tac
 * @date : 28/07/2017
 */
@Repository
public class UserRoleRelationDao extends GenericBizDao<UserRoleRelation, String> {
    @Autowired
    public UserRoleRelationDao(UserRoleRelationMapper mapper) {
        super(mapper);
    }

    /**
     * 批量新增
     */
    public int insertBatch(Collection<Role> roles) {
        //todo::
        return 0;
    }

    public int selectCountByRoleId(String roleId) {
        UserRoleRelation o = new UserRoleRelation();
        o.setRoleId(roleId);
        return selectCount(o);
    }

    public List<UserRoleRelation> selectByUserId(String userId) {
	    UserRoleRelation userRoleRelation = new UserRoleRelation();
	    userRoleRelation.setUserId(userId);
    	return select(userRoleRelation);
    }

	public List<UserRoleRelation> selectByUserIds(Set<String> accountIds) {
		Example example = new Example(UserRoleRelation.class);
		example.createCriteria().andIn("userId", accountIds);
		return selectByExample(example);
	}
}
